package com.cipta.lomob.utils;

import android.util.Log;

/**
*
* @author S Dedi Nirtadinata
* @date August, 27, 2014
* 
* this class used as helper to find out how height or width resize by aspect ration
*/
public class AspectRatio {
	
	//yang dicari apakah di resize by width atau by height
	//jika ratio 
	
	public static int findHeigth(int originalWidth, int originalHeight, int newWidht){
		//first find gcd
		int gcd = findGCD(originalWidth, originalHeight);
		int ratioWidth = originalWidth/gcd;
		int ratioHeight = originalHeight/gcd;
		
		int newHeight = (newWidht/ratioWidth) * ratioHeight;
		return newHeight;
	}
	
	public static int findWidht(int originalWidth, int originalHeight, int newHeight){
		Log.i("Aspect Ration", "size: " + originalWidth + " x " + originalHeight);
		//first find gcd
		int gcd = findGCD(originalWidth, originalHeight);
		int ratioWidth = originalWidth/gcd;
		int ratioHeight = originalHeight/gcd;
		
		int newWidth = (newHeight/ratioHeight) * ratioWidth;
		return newWidth;
	}
	
	private static int findGCD(int a, int b){
		if(b == 0) {
			return a;
		}else{
			return findGCD(b, a%b);
		}
	}
}
